import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:navigate_demo/screens/payment_screen.dart';

import '../routes/router_names.dart';
import '../widgets/navigation_card.dart';
import 'args/detail_args.dart';
import 'basic_screen.dart';
import 'detail_screen.dart';

class HomeScreen extends StatelessWidget{
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('导航系统演示'),
        centerTitle: true,
      ),
      body:  Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const SizedBox(height: 20),
            const Text(
              'Flutter 导航系统',
              style: TextStyle(fontSize: 24,fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 10),
            const  Text(
              '多种导航方式和参数传递实现',
              style: TextStyle(fontSize: 16, color: Colors.grey),
              textAlign: TextAlign.center,
            ),
            const  SizedBox(height: 30),
            Expanded(
                child: ListView(
                  children: [
                    NavigationCard(
                      icon:Icons.navigation,
                      title:'基础导航',
                      subtitle:'使用 Navigator.push 实现简单跳转',
                      onTap: (){
                        Navigator.push(context,
                            MaterialPageRoute(
                                builder: (context)=>const BasicScreen()));
                      },
                    ),
                    NavigationCard(
                      icon:Icons.send,
                      title:'构造函数传参',
                      subtitle:'通过页面构造函数传递参数',
                      color: Colors.blue[700],
                      onTap: (){
                        Navigator.push(context,
                            MaterialPageRoute(
                                builder: (context)=>const DetailScreen(
                                  productId:1001,
                                  productName:'高端手机',
                                )));
                      }),
                      NavigationCard(
                        icon: Icons.alt_route,
                        title: '命名路由传参',
                        subtitle: '通过路由参数传递数据',
                        color: Colors.green[700],
                        onTap: () {
                          Navigator.pushNamed(
                            context,
                            RouterNames.detail,
                            arguments: DetailArgs(
                              productId: 2002,
                              productName: '智能手表',
                            ),
                          );
                        },
                    ),NavigationCard(
                      icon: Icons.payment,
                      title: '返回结果处理',
                      subtitle: '等待页面返回结果',
                      color:  Colors.purple[700],
                      onTap: () async {
                        final result = await Navigator.push(context,
                        MaterialPageRoute(builder: (context)=>PaymentScreen()));
                        if(result!=null && context.mounted){
                          ScaffoldMessenger.of(context).showSnackBar(
                            SnackBar(content: Text('支付结果：${result['status']}'),
                              backgroundColor:  result['status'] == '支付成功' 
                              ?Colors.green:Colors.red ,
                            ),
                          );
                        }
                      },
                    ),
                    NavigationCard(
                        icon: Icons.settings,
                        title: '动态路由生成',
                        subtitle: '使用 onGenerateRoute 实现',
                        color: Colors.orange[700],
                        onTap: (){
                          Navigator.pushNamed(context, RouterNames.settings);
                        })
                  ],
                )),
          ],
        ),
      ),
    );
  }
}